#!/usr/bin/env node

const Event = require('./05-event');

class Dog extends Event {
  #name="";
  #energy=0;

  constructor(name, energy) {
    super();
    this.#name = name;
    this.#energy = energy;
    this.barkInterval = setInterval(() => {
      if (this.#energy > 0) {
        this.emit('bark', this.#name);
        this.#energy--;
      } else {
        clearInterval(this.barkInterval);
      }
    }, 1000);
  }

  getEnergy() {
    return this.#energy;
  }

  setEnergy(energy) {
    this.#energy = energy;
  }
}

module.exports = Dog;